<?php


namespace App\Service\Admin;


use App\Dao\AdminMenuDao;
use App\Model\AdminMenu;
use Hyperf\Di\Annotation\Inject;

class AdminMenuService
{

    /**
     * @Inject()
     * @var AdminMenuDao
     */
    protected $adminMenuDao;

    public function save($id, array $data): bool
    {
        if ($id) {
            $adminMenu = $this->adminMenuDao->first(['id' => $id]);
        } else {
            $adminMenu = new AdminMenu();
        }

        $adminMenu->fill($data);
        return $adminMenu->save();
    }

    public function tree()
    {
        return $this->adminMenuDao->getMenuTree([]);
    }

}